<?php

namespace App\Http\Controllers\Admin\v1;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Controllers\ApiController;
use App\Services\EasySms\EasySmsService;
use App\Exceptions\ApiErrCode;

class TestController extends ApiController
{
    //
    public function index(Request $request)
    {
        $data=[];
        $data['endpoint']=$request->route()->getName();
        $data['host'] = $request->getClientIp();
        $data['info']='Guangzhou PanX Software Developments Co., Ltd';
        $data['url'] = $request->url();
        return $this->response(compact('data'));
    }

    public function sendVerifyCodeSMS(Request $request)
    {
        $area_code = $request->get('area_code');
        $phone = $request->get('phone');
        $type = (int) $request->get('type');  //0：注册验证码；其他：登录验证码

        $verify_code = (string) \rand(100000,999999);
        if($type == 0){
            (new EasySmsService)->registerSend($phone,$verify_code, $area_code);
        }else{
            (new EasySmsService)->loginSend($phone, $verify_code, $area_code);
        }

        // $error = ApiErrCode::

        return $this->response(compact('verify_code'));
    }

    
}
